package com.lzh.walletdemo.controller;

import com.lzh.walletdemo.entity.LogAmount;
import com.lzh.walletdemo.service.UserOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/operation")
public class UserOperationController {
    @Autowired
    private UserOperationService userOperationService;
    /**
     * 查询用户钱包余额
     * @param userId 用户id
     * @return 返回余额
     */
    @GetMapping("/getBalance")
    public String getUserBalance(Integer userId){
        return "用户余额为:" + userOperationService.getBalance(userId);
    }
    /**
     * 用户支付数额
     * @param payMoney 花费钱数
     * @param userId 用户id
     * @return 消费成功/消费失败
     */
    @PutMapping("/decrease")
    public String pay(BigDecimal payMoney,Integer userId){
        return userOperationService.pay(payMoney,userId);
    }
    /**
     * 用户退费
     * @param backMoney 退费金额
     * @param userId 用户id
     * @return 退费成功/退费失败
     */
    @PostMapping("/increase")
    public String balanceBack(BigDecimal backMoney,Integer userId){
        return userOperationService.balanceBack(backMoney,userId);
    }
    /**
     * 查询用户钱包金额变动情况
     * @param userId 用户id
     * @return 返回用户的所有金额变动情况
     */
    @GetMapping("/getLog")
    public List<Map<String,Object>> getAmountLog(Integer userId){
        return userOperationService.getAmountLog(userId);
    }

}
